<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>partikkelsync</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="partikkel.html" title="partikkel" />
    <link rel="next" href="passign.html" title="passign" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">partikkelsync</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="partikkel.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="passign.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="partikkelsync"></a>
      <div class="titlepage"></div>
      <a id="IndexPartikkelsync" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">partikkelsync</span>
        </h2>
        <p>partikkelsync —  Outputs <span class="emphasis"><em>partikkel</em></span>'s grain
      scheduler clock pulse and phase to synchronize several instances of the <span class="emphasis"><em>partikkel</em></span>
      opcode to the same clock source.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132714400"></a>
        <h2>Description</h2>
        <p>
      <span class="emphasis"><em>partikkelsync</em></span> is an opcode for outputting <a class="link" href="partikkel.html" title="partikkel"><em class="citetitle">partikkel</em></a>'s grain scheduler clock pulse and phase. <span class="emphasis"><em>partikkelsync</em></span>'s output can be used to synchronize other instances of the <a class="link" href="partikkel.html" title="partikkel"><em class="citetitle">partikkel</em></a> opcode to the same clock.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132718432"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">async [,aphase] <span class="command"><strong>partikkelsync</strong></span> iopcode_id</pre>
      </div>
      <div class="refsect1">
        <a id="idp132720640"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iopcode_id</em></span> -- the opcode id, linking an
      instance of <a class="link" href="partikkel.html" title="partikkel"><em class="citetitle">partikkel</em></a> to an instance of <span class="emphasis"><em>partikkelsync</em></span>. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132723712"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>async</em></span> -- trigger pulse signal. 
      Outputs trigger pulses synchronized to a <span class="emphasis"><em>partikkel</em></span> opcode's grain scheduler clock. 
      One trigger pulse is generated for each grain started in the <span class="emphasis"><em>partikkel</em></span> opcode with the same <span class="emphasis"><em>opcode_id</em></span>.
      The normal usage would be to send this signal to another <span class="emphasis"><em>partikkel</em></span> opcode's <span class="emphasis"><em>async</em></span> input to 
      synchronize several instances of <span class="emphasis"><em>partikkel</em></span>.
    </p>
        <p>
      <span class="emphasis"><em>aphase</em></span> -- clock phase. 
      Outputs a linear ramping phase signal. Can be used e.g. for softsynchronization, or just as a phase generator ala <span class="emphasis"><em>phasor</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132729664"></a>
        <h2>Example</h2>
        <p>
      Here is an example of the partikkelsync opcodes. It uses the file <a class="ulink" href="examples/partikkelsync.csd" target="_top"><em class="citetitle">partikkelsync.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp132731552"></a>
          <p class="title">
            <strong>Example 603. Example with soft sync of two partikkel generators.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out  </span>
-odac           <span class="comment">;;;RT audio </span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o partikkel_softsync.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 20
<span class="ohdr">nchnls</span> <span class="op">=</span> 2

<span class="comment">; Example by Oeyvind Brandtsegg 2007, revised 2008</span>

giSine		<span class="ohdr">ftgen</span>	0, 0, 65537, 10, 1
giCosine	<span class="ohdr">ftgen</span>	0, 0, 8193, 9, 1, 1, 90
giSigmoRise	<span class="ohdr">ftgen</span>		0, 0, 8193, 19, 0.5, 1, 270, 1			<span class="comment">; rising sigmoid </span>
giSigmoFall	<span class="ohdr">ftgen</span>		0, 0, 8193, 19, 0.5, 1, 90, 1			<span class="comment">; falling sigmoid </span>

<span class="comment">; *************************************************</span>
<span class="comment">; example of soft synchronization of two partikkel instances</span>
<span class="comment">; *************************************************</span>
	<span class="oblock">instr</span> 1


<span class="op">/</span><span class="op">*</span>score parameters<span class="op">*</span><span class="op">/</span>
igrainrate	<span class="op">=</span> p4		<span class="comment">; grain rate</span>
igrainsize	<span class="op">=</span> p5		<span class="comment">; grain size in ms</span>
igrainFreq	<span class="op">=</span> p6		<span class="comment">; fundamental frequency of source waveform</span>
iosc2Dev	<span class="op">=</span> p7		<span class="comment">; partikkel instance 2 grain rate deviation factor</span>
iMaxSync	<span class="op">=</span> p8		<span class="comment">; max soft sync amount (increasing to this value during length of note)</span>

<span class="op">/</span><span class="op">*</span>overall envelope<span class="op">*</span><span class="op">/</span>
iattack		<span class="op">=</span> 0.001
idecay		<span class="op">=</span> 0.2
isustain	<span class="op">=</span> 0.7
irelease	<span class="op">=</span> 0.2
amp		<span class="opc">linsegr</span>	0, iattack, 1, idecay, isustain, 1, isustain, irelease, 0

kgrainfreq	<span class="op">=</span> igrainrate		<span class="comment">; grains per second</span>
kdistribution	<span class="op">=</span> 0			<span class="comment">; periodic grain distribution</span>
idisttab	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; (default) flat distribution used</span>
                                        <span class="comment">; for grain distribution</span>
async		<span class="op">=</span> 0			<span class="comment">; no sync input</span>
kenv2amt	<span class="op">=</span> 0			<span class="comment">; no secondary enveloping</span>
ienv2tab	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; default secondary envelope (flat)</span>
ienv_attack	<span class="op">=</span> giSigmoRise		<span class="comment">; default attack envelope (flat)</span>
ienv_decay	<span class="op">=</span> giSigmoFall		<span class="comment">; default decay envelope (flat)</span>
ksustain_amount	<span class="op">=</span> 0.3			<span class="comment">; time (in fraction of grain dur) at</span>
                                        <span class="comment">; sustain level for each grain</span>
ka_d_ratio	<span class="op">=</span> 0.2 			<span class="comment">; balance between attack and decay time</span>
kduration	<span class="op">=</span> igrainsize		<span class="comment">; set grain duration in ms</span>
kamp		<span class="op">=</span> 0.2<span class="op">*</span><span class="ohdr">0dbfs</span> 		<span class="comment">; amp</span>
igainmasks	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; (default) no gain masking</span>
kwavfreq	<span class="op">=</span> igrainFreq		<span class="comment">; fundamental frequency of source waveform</span>
ksweepshape	<span class="op">=</span> 0			<span class="comment">; shape of frequency sweep (0=no sweep)</span>
iwavfreqstarttab <span class="op">=</span> <span class="op">-</span>1			<span class="comment">; default frequency sweep start</span>
                                        <span class="comment">; (value in table = 1, which give</span>
                                        <span class="comment">; no frequency modification)</span>
iwavfreqendtab	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; default frequency sweep end</span>
                                        <span class="comment">; (value in table = 1, which give</span>
                                        <span class="comment">; no frequency modification)</span>
awavfm		<span class="op">=</span> 0			<span class="comment">; no FM input</span>
ifmamptab	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; default FM scaling (=1)</span>
kfmenv		<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; default FM envelope (flat)</span>
icosine		<span class="op">=</span> giCosine		<span class="comment">; cosine ftable</span>
kTrainCps	<span class="op">=</span> kgrainfreq		<span class="comment">; set trainlet cps equal to grain</span>
                                        <span class="comment">; rate for single-cycle trainlet in</span>
                                        <span class="comment">; each grain</span>
knumpartials	<span class="op">=</span> 3			<span class="comment">; number of partials in trainlet</span>
kchroma		<span class="op">=</span> 1			<span class="comment">; balance of partials in trainlet</span>
ichannelmasks	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; (default) no channel masking,</span>
                                        <span class="comment">; all grains to output 1</span>
krandommask	<span class="op">=</span> 0			<span class="comment">; no random grain masking</span>
kwaveform1	<span class="op">=</span> giSine		<span class="comment">; source waveforms</span>
kwaveform2	<span class="op">=</span> giSine		<span class="comment">;</span>
kwaveform3	<span class="op">=</span> giSine		<span class="comment">;</span>
kwaveform4	<span class="op">=</span> giSine		<span class="comment">;</span>
iwaveamptab	<span class="op">=</span> <span class="op">-</span>1			<span class="comment">; mix of 4 source waveforms and</span>
                                        <span class="comment">; trainlets (set to default)</span>
asamplepos1	<span class="op">=</span> 0			<span class="comment">; phase offset for reading source waveform</span>
asamplepos2	<span class="op">=</span> 0			<span class="comment">;</span>
asamplepos3	<span class="op">=</span> 0			<span class="comment">;</span>
asamplepos4	<span class="op">=</span> 0			<span class="comment">;</span>
kwavekey1	<span class="op">=</span> 1			<span class="comment">; original key for source waveform</span>
kwavekey2	<span class="op">=</span> 1			<span class="comment">;</span>
kwavekey3	<span class="op">=</span> 1			<span class="comment">;</span>
kwavekey4	<span class="op">=</span> 1			<span class="comment">;</span>
imax_grains	<span class="op">=</span> 100			<span class="comment">; max grains per k period</span>
iopcode_id	<span class="op">=</span> 1			<span class="comment">; id of opcode, linking partikkel</span>
                                        <span class="comment">; to partikkelsync</span>

a1  <span class="opc">partikkel</span> kgrainfreq, kdistribution, idisttab, async, kenv2amt, \
       ienv2tab,ienv_attack, ienv_decay, ksustain_amount, ka_d_ratio, \
       kduration, kamp, igainmasks, kwavfreq, ksweepshape, \
       iwavfreqstarttab, iwavfreqendtab, awavfm, ifmamptab, kfmenv, \
       icosine, kTrainCps, knumpartials, kchroma, ichannelmasks, \
       krandommask, kwaveform1, kwaveform2, kwaveform3, kwaveform4, \
       iwaveamptab, asamplepos1, asamplepos2, asamplepos3, asamplepos4, \
       kwavekey1, kwavekey2, kwavekey3, kwavekey4, imax_grains, iopcode_id

async1		<span class="opc">partikkelsync</span>	iopcode_id   <span class="comment">; clock pulse output of the </span>
                                             <span class="comment">; partikkel instance above</span>
ksyncGravity 	<span class="opc">line</span> 0, p3, iMaxSync	     <span class="comment">; strength of synchronization</span>
aphase2		<span class="opc">init</span> 0					
asyncPolarity	limit (<span class="opc">int</span>(aphase2<span class="op">*</span>2)<span class="op">*</span>2)<span class="op">-</span>1, <span class="op">-</span>1, 1
<span class="comment">; use the phase of partikkelsync instance 2 to find sync </span>
<span class="comment">; polarity for partikkel instance 2.</span>
<span class="comment">; If the phase of instance 2 is less than 0.5, we want to</span>
<span class="comment">; nudge it down when synchronizing,</span>
<span class="comment">; and if the phase is &gt; 0.5 we want to nudge it upwards.</span>
async1		<span class="op">=</span> async1<span class="op">*</span>ksyncGravity<span class="op">*</span>asyncPolarity  <span class="comment">; prepare sync signal</span>
                                                  <span class="comment">; with polarity and strength</span>

kgrainfreq2	<span class="op">=</span> igrainrate <span class="op">*</span> iosc2Dev		<span class="comment">; grains per second for second partikkel instance</span>
iopcode_id2	<span class="op">=</span> 2
a2 <span class="opc">partikkel</span> kgrainfreq2, kdistribution, idisttab, async1, kenv2amt, \
       ienv2tab, ienv_attack, ienv_decay, ksustain_amount, ka_d_ratio, \
       kduration, kamp, igainmasks, kwavfreq, ksweepshape, \
       iwavfreqstarttab, iwavfreqendtab, awavfm, ifmamptab, kfmenv, \
       icosine, kTrainCps, knumpartials, kchroma, ichannelmasks, \
       krandommask, kwaveform1, kwaveform2, kwaveform3, kwaveform4, \
       iwaveamptab, asamplepos1, asamplepos2, asamplepos3, \ 
       asamplepos4, kwavekey1, kwavekey2, kwavekey3, kwavekey4, \
       imax_grains, iopcode_id2

async2, aphase2	<span class="opc">partikkelsync</span>	iopcode_id2
<span class="comment">; clock pulse and phase </span>
<span class="comment">; output of the partikkel instance above,</span>
<span class="comment">; we will only use the phase</span>

<span class="opc">outs</span>	a1<span class="op">*</span>amp, a2<span class="op">*</span>amp

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

/*score parameters
<span class="stamnt">i</span>gra<span class="stamnt">i</span>nrate	= p4		<span class="comment">; grain rate</span>
<span class="stamnt">i</span>gra<span class="stamnt">i</span>ns<span class="stamnt">i</span>ze	= p5		<span class="comment">; grain size in ms</span>
<span class="stamnt">i</span>gra<span class="stamnt">i</span>nFreq	= p6		<span class="comment">; frequency of source wave within grain</span>
<span class="stamnt">i</span>osc2Dev	= p7		<span class="comment">; partikkel instance 2 grain rate deviation factor</span>
<span class="stamnt">i</span>MaxSync	= p8		<span class="comment">; max soft sync amount (increasing to this value during length of note)</span>
*/
<span class="comment">;		GrRate	GrSize	GrFund	Osc2Dev	MaxSync</span>

<span class="stamnt">i</span>1 0 	10	2	20	880	1.3	0.3
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	10	5	20	440	0.8	0.3	
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	6	55	15	660	1.8	0.45
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	6	110	10	440	0.6	0.6	
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	6	220	3	660	2.6	0.45
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	6	220	3	660	2.1	0.45
<span class="stamnt">s</span>
<span class="stamnt">i</span>1 0 	6	440	3	660	0.8	0.22
<span class="stamnt">s</span>

<span class="stamnt">e</span>

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132735856"></a>
        <h2>See Also</h2>
        <p><a class="link" href="partikkel.html" title="partikkel"><em class="citetitle">partikkel</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp132737776"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Thom Johansen</td>
          </tr>
          <tr>
            <td>Author: Torgeir Strand Henriksen</td>
          </tr>
          <tr>
            <td>Author: Øyvind Brandtsegg</td>
          </tr>
          <tr>
            <td>April 2007</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 5.06</p>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="partikkel.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="passign.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">partikkel </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> passign</td>
        </tr>
      </table>
    </div>
  </body>
</html>
